package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/news")
@Api(tags = "查询自媒体文章")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询自媒体文章
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("/list")
    @ApiOperation("查询自媒体文章")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto wmNewsPageReqDto) {
        return wmNewsService.findAll(wmNewsPageReqDto);
    }

    /**
     * 文章发布
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    @ApiOperation("文章发布")
    public ResponseResult submitNews(@RequestBody WmNewsDto wmNewsDto){
        return  wmNewsService.submitNews(wmNewsDto);
    }

    /**
     * 文章上下架
     * @param newsDto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult dowOrUp(@RequestBody WmNewsDto wmNewsDto){
        return wmNewsService.dowOrUp(wmNewsDto);
    }
}
